//2009/08/15 01:55:23
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;
#define MMAX		1000 // It can be set 51, since the number of commands is less than 50;
struct sel
{
    int arc;
    int cir;
    int pol;
    sel(int a, int b, int c)
    {
        arc = a;
        cir = b;
        pol = c;
    }
};
class grafixGlobs
{
public:
    vector <int> execute(vector <string> commands, int se)
    {
        vector<sel> v;
        vector<int> res;
        string s;
        for (int i=0; i<MMAX; i++)	v.push_back(sel(0,0,0));
        for (int i=0; i<commands.size(); i++)
        {
            stringstream cmd(commands[i]);
            cmd >> s;
            if (s == "make")
            {
                int j;
                for (j=0; j<MMAX; j++)
                    if (v[j].arc == 0 && v[j].cir == 0 && v[j].pol == 0) break;
                cmd >> s;
                if (s == "arc") v[j].arc ++;
                if (s == "circle") v[j].cir ++;
                if (s == "polygon") v[j].pol ++;
            }
            else if (s == "delete")
            {
                int j;
                cmd >> j;
                v[j].arc = 0;
                v[j].cir = 0;
                v[j].pol = 0;
            }
            else if (s == "merge")
            {
                int src, des;
                cmd >> des;
                cmd >> src;
                v[des].arc += v[src].arc;
                v[src].arc = 0;
                v[des].cir += v[src].cir;
                v[src].cir = 0;
                v[des].pol += v[src].pol;
                v[src].pol = 0;
            }
            else if (s == "split")
            {
                int src;
                cmd >> src;
                int t1 = v[src].arc;
                v[src].arc = 0;
                int t2 = v[src].cir;
                v[src].cir = 0;
                int t3 = v[src].pol;
                v[src].pol = 0; 
				// Here, the new splited item can be rearranged in the original sel.
                for (int j=0; j<1000; j++)
                {
                    if (v[j].arc + v[j].cir + v[j].pol == 0)
                    {
                        if (t1 > 0)
                        {
                            v[j].arc ++;
                            t1 --;
                        }
                        else if (t2 > 0)
                        {
                            v[j].cir ++;
                            t2 --;
                        }
                        else if (t3 > 0)
                        {
                            v[j].pol ++;
                            t3 --;
                        }
                    }
                    if (t1 + t2 + t3 == 0) break;
                }
            }
        }
        if (v[se].arc + v[se].cir + v[se].pol > 0)
        {
            res.push_back(v[se].arc);
            res.push_back(v[se].cir);
            res.push_back(v[se].pol);
        }
        return res;
    }
};
